<extend name="Public:base" />

<block name="additional-styles">
	<!-- DataTables -->
	<link rel="stylesheet" href="__PUBLIC__/Admin/plugins/datatables/dataTables.bootstrap.css" />
</block>

<block name="content-wrapper">
	<!-- Content Wrapper. Contains page content -->
	<div class="content-wrapper">
		<!-- Content Header (Page header) -->
		<section class="content-header">
			<h1>
				我的作业
				<small>My Homework</small>
			</h1>
			<ol class="breadcrumb">
				<li>
					<a href="{:U('Index/index')}"> <i class="fa fa-dashboard"></i>
						首页
					</a>
				</li>
				<li class="active">我的作业</li>
			</ol>
		</section>

		<!-- Main content -->
		<section class="content">
			<div class="row">
				<div class="col-xs-12">
					<div class="box">
						<div class="box-header">
							<!-- <h3 class="box-title">Data Table With Full Features</h3>-->
							<div class="row">
								<form id="form-index" class="form-horizontal" action="{:U('MyHomework/index')}" method="post">
									<div class="col-xs-4">
										<div class="form-group">
											<label class="col-sm-3 control-label">逻辑班级</label>
											<div class="col-sm-9">
												<select name="logic_class_id" id="logic_class_id" class="form-control">
													<volist name="logic_classes" id="vo">
														<eq name="vo.id" value="$logic_class_id">
															<option value="{$vo.id}" selected="selected">{$vo.name}</option>
														<else />
															<option value="{$vo.id}">{$vo.name}</option>
														</eq>
													</volist>											
								                </select>
											</div>
										</div>										
									</div>
								</form>
							</div>
						</div>
						<!-- /.box-header -->
						<div class="box-body">
							<table id="example1" class="table table-bordered table-striped">
								<thead>
									<tr>
										<th>ID</th>
										<th>作业标题</th>
										<th>作业内容</th>
										<th>开始时间</th>
										<th>截止时间</th>
										<th>提交情况</th>
										<th>得分</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody>
									<volist name="homeworks" id="vo">
										<tr>
											<td>{$vo.id}</td>
											<td>{$vo.title}</td>
											<td>{$vo.content}</td>
											<td>{:date('Y/m/d H:i', $vo['start_time'])}</td>
											<td>{:date('Y/m/d H:i', $vo['end_time'])}</td>
											<php>
												$submit_result = '';
												switch(is_homework_submitted($vo['id'])) {
													case 0:
														$submit_result = '未提交';
														break;
													case 1:
														$submit_result = '超时提交';
														break;
													case 2:
														$submit_result = '准时提交';
														break;
												}
											</php>
											<td>{$submit_result}</td>
											<php>
												$score = is_homework_scored($vo['id']);
												$score = false === $score? '未打分' : $score;
											</php>
											<td>{$score}</td>
											<td>
												<a href="{:U('MyHomework/detail', array('homework_id' => $vo['id']))}" class="btn btn-default btn-sm">详情</a>
												<eq name="score" value="未打分">
													<a href="{:U('MyHomework/submit', array('homework_id' => $vo['id']))}" class="btn btn-default btn-sm">提交</a>
												<else />
													<a class="btn btn-default btn-sm" disabled="disabled">提交</a>
												</eq>
											</td>
										</tr>
									</volist>
								</tbody>
								<tfoot>
									<tr>
										<th>ID</th>
										<th>作业标题</th>
										<th>作业内容</th>
										<th>开始时间</th>
										<th>截止时间</th>
										<th>提交情况</th>
										<th>得分</th>
										<th>操作</th>
									</tr>
								</tfoot>
							</table>
						</div>
						<!-- /.box-body -->
					</div>
					<!-- /.box -->
				</div>
			</div>
		</section>
		<!-- /.content -->
	</div>
	<!-- /.content-wrapper -->
	<!-- 删除逻辑班级学生 模态框 -->
	<div class="modal" id="modal-delete">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">×</span>
					</button>
					<h4 class="modal-title">删除记录</h4>
				</div>
				<div class="modal-body">
					<div class="container-fluid">
						<div class="row">
							<form id="form-delete" class="form-horizontal" action="{:U('Homework/deletePost')}" method="post">
								<div class="form-group">
									<input name="id" id="id" type="hidden">
									<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;确定删除？</p>
								</div>
							</form>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default pull-left" data-dismiss="modal">取消</button>
					<button id="button-delete-submit"type="button" class="btn btn-primary">确定</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- /.modal -->
</block>

<block name="additional-scripts">
	<!-- DataTables -->
	<script src="__PUBLIC__/Admin/plugins/datatables/jquery.dataTables.min.js"></script>
	<script src="__PUBLIC__/Admin/plugins/datatables/dataTables.bootstrap.min.js"></script>
	<script>
		$(function () {
			$("#example1").DataTable();
			$('#example2').DataTable({
				"paging": true,
				"lengthChange": false,
				"searching": false,
				"ordering": true,
				"info": true,
				"autoWidth": false
			});

			$('#logic_class_id').change(function() {
				$('#form-index').submit();
			});

			$('#modal-delete').on('show.bs.modal', function(event) {
				var button = $(event.relatedTarget);
				var id = button.data('whatever');
				$('#modal-delete').find('.modal-body #id').val(id);
			});
			$('#button-delete-submit').click(function() {
				$('#form-delete').submit();
			});
		});
	</script>
</block>